package com.cy.pj.sys.service.impl;

import com.cy.pj.sys.dao.SysStuProDao;
import com.cy.pj.sys.dao.SysStudentDao;
import com.cy.pj.sys.pojo.SysStudent;
import com.cy.pj.sys.service.SysStudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SysStudentServiceImpl implements SysStudentService {
    @Autowired
    private SysStudentDao sysStudentDao;
    @Autowired
    private SysStuProDao sysStuProDao;

    @Override
    public List<SysStudent> findStudent(SysStudent sysStudent) {
        return sysStudentDao.selectStu(sysStudent);
    }

    @Override
    public SysStudent selectById(Long id) {
        return sysStudentDao.selectById(id);
    }

    @Override
    public Integer insertStu(SysStudent sysStudent) {

        Integer rows = sysStudentDao.insertStu(sysStudent);

        //关系表新增
        sysStuProDao.insertStudentProduct(sysStudent.getId(),sysStudent.getTypes());

        return rows;



    }

    @Override
    public Integer deleteById(Long id) {
        Integer rows =  sysStudentDao.deleteById(id);
        sysStuProDao.deleteById(id);
        return rows;


    }

    @Override
    public Integer updateStu(SysStudent sysStudent) {
        Integer rows = sysStudentDao.updateStu(sysStudent);
        sysStuProDao.deleteById(sysStudent.getId());

        sysStuProDao.insertStudentProduct(sysStudent.getId(),sysStudent.getTypes());
        return rows;
    }

}
